'''
陈超依 19377189
现代程序设计第四次作业
'''

from matplotlib import pyplot as plt
from GraphStat.NetworkBuilder import stat

def plot_character(LNodes, character):
    '''统计某一属性在各职业间的占比,绘制扇形图'''
    L = stat.character_spare(LNodes, character)
    result = [0, 0, 0] #starring, writer, director
    for i in L:
        career = i['type_']
        if (career == 'starring'):
            result[0] = result[0] + 1
        if (career == 'writer'):
            result[1] = result[1] + 1
        if(career == 'director'):
            result[2] = result[2] + 1
    fig,axes = plt.subplots()
    axes.pie(result, explode=[0,0,0], autopct='%.2f%%',\
        labels=['starring', 'writer', 'director'], startangle=90)
    axes.set_aspect('equal')
    axes.set_title('属性 {} 的各职业分布'.format(character))
    fig.savefig('E:/Py_Programs/week4/character.png')